package com.abvnet.project.water.project.controller;

import com.abvnet.common.utils.StringUtils;
import com.abvnet.common.utils.security.ShiroUtils;
import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.project.domain.ProjectCustomerEval;
import com.abvnet.project.water.project.service.IProjectCustomerEvalService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户评价信息操作处理
 * 
 * @author duj
 * @date 2019-08-17
 */
@Controller
@RequestMapping("/project/projectCustomerEval")
public class ProjectCustomerEvalController extends BaseController {
    private String prefix = "project/projectCustomerEval";
	
	@Autowired
	private IProjectCustomerEvalService projectCustomerEvalService;
	
	@RequiresPermissions("project:projectCustomerEval:list")
	@GetMapping()
	public String projectCustomerEval()
	{
	    return prefix + "/list";
	}
	
	/**
	 * 查询客户评价列表
	 */
	@RequiresPermissions("project:projectCustomerEval:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProjectCustomerEval projectCustomerEval) {
        if (StringUtils.equals("1", ShiroUtils.getSysUser().getUserType())) {
            projectCustomerEval.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
		startPage();
        List<ProjectCustomerEval> list = projectCustomerEvalService.selectProjectCustomerEvalList(projectCustomerEval);
		return getDataTable(list);
	}

	/**
	 * 新增客户评价
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户评价
	 */
	@RequiresPermissions("project:projectCustomerEval:add")
	@Log(title = "客户评价", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProjectCustomerEval projectCustomerEval) {
		return toAjax(projectCustomerEvalService.insertProjectCustomerEval(projectCustomerEval));
	}

	/**
	 * 修改客户评价
	 */
	@GetMapping("/edit/{evalId}")
	public String edit(@PathVariable("evalId") Long evalId, ModelMap mmap) {
		ProjectCustomerEval projectCustomerEval = projectCustomerEvalService.selectProjectCustomerEvalById(evalId);
		mmap.put("projectCustomerEval", projectCustomerEval);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客户评价
	 */
	@RequiresPermissions("project:projectCustomerEval:edit")
	@Log(title = "客户评价", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProjectCustomerEval projectCustomerEval) {
		return toAjax(projectCustomerEvalService.updateProjectCustomerEval(projectCustomerEval));
	}
	
	/**
	 * 删除客户评价
	 */
	@RequiresPermissions("project:projectCustomerEval:remove")
	@Log(title = "客户评价", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(projectCustomerEvalService.deleteProjectCustomerEvalByIds(ids));
	}

    @GetMapping("/view/{evalId}")
    public String view(@PathVariable("evalId") Long evalId, ModelMap mmap) {
        ProjectCustomerEval projectCustomerEval = projectCustomerEvalService.selectProjectCustomerEvalById(evalId);
        mmap.put("projectCustomerEval", projectCustomerEval);
        return prefix + "/view";
    }
}
